package com.weiyuwqj.admin.controller.admin.picture;

import com.weiyuwqj.admin.controller.admin.log.annotation.LogAnnotation;
import com.weiyuwqj.api.service.SysPictureTypeService;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.constant.Message;
import com.weiyuwqj.api.model.SysPictureType;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2015/12/7.
 */
@Controller
@RequestMapping(value="/admin/picture_type")
public class SysPictureTypeController {
    @Autowired
    SysPictureTypeService sysPictureTypeService;
    //显示
    @ResponseBody
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Object list(Paginator paginator,HttpServletRequest request){
        String name = request.getParameter("name");
        String beginDateTime = request.getParameter("beginDateTime");
        String endDateTime = request.getParameter("endDateTime");
        Map<String, Object> map = new HashMap<String, Object>();
        if(StringUtils.isNotEmpty(name)){
            map.put("name", name);
        }
        if(StringUtils.isNotEmpty(beginDateTime)){
            map.put("beginDateTime", beginDateTime);
        }
        if(StringUtils.isNotEmpty(endDateTime)){
            map.put("endDateTime", endDateTime);
        }
        return sysPictureTypeService.getList(paginator, map);
    }

    //增加
    @ResponseBody
    @RequestMapping("/add")
    @LogAnnotation(module ="图片类型",description = "增加")
    public Object add(SysPictureType picture){
        sysPictureTypeService.save(picture);
        return Message.OK;
    }
    //获取编辑信息
    @ResponseBody
    @RequestMapping(value = "/getSingle",method = RequestMethod.POST)
    public Object getSingle(Integer id) {
        return sysPictureTypeService.getSingle(id);
    }
    //编辑
    @ResponseBody
    @RequestMapping(value="/edit",method = RequestMethod.POST)
    @LogAnnotation(module ="图片类型",description = "编辑")
    public void edit(SysPictureType picture){
        sysPictureTypeService.updateNotNull(picture);
    }
}
